package com.mdxx.xczd.manager;

import android.content.Context;

import java.nio.ByteBuffer;

import veg.mediaplayer.sdk.MediaPlayer;
import veg.mediaplayer.sdk.MediaPlayer.MediaPlayerCallback;

public class MediaPlayerManager {
	private static MediaPlayerManager mediaPlayerManager;
	private MediaPlayer player;
	private MediaPlayerManager(Context context){
		init(context);
	}
	
	public static MediaPlayerManager getInstance(Context context){
		if(mediaPlayerManager == null){
			synchronized (AudioManagerUtil.class) {
				if(mediaPlayerManager == null){
					mediaPlayerManager = new MediaPlayerManager(context);
				}
			}
		}
		return mediaPlayerManager;
	}
	
	private void init(Context context){
		player = new MediaPlayer(context, false);
	}
	
	public void stopPlayAudio() {
		player.Stop();
		player.Close();
	}
	
	public void startPlayAudio(String rtspUrl) {
		int Time = player.getConfig().getDataReceiveTimeout();
		player.Open(rtspUrl, Time, mediaPlayerCallback);
		player.setVolumeBoost(20);
		player.Play();
	}
	
	private MediaPlayerCallback mediaPlayerCallback = new MediaPlayerCallback(){

		@Override
		public int OnReceiveData(ByteBuffer arg0, int arg1, long arg2) {
			return 0;
		}

		@Override
		public int Status(int arg0) {
			return 0;
		}
		
	};
}
